import { BaseModule } from '../../../lib/abstract'
import { logger } from '../../../types/constants'
import { ConfigManager } from '../../config_manager'

interface Config {
  enabled?: boolean
}

export class BlockLogin extends BaseModule {
  readonly id: string = 'block_login'
  readonly name: string = 'BlockLogin'
  readonly supportedPlatforms: string[] = ConfigManager.getInstance().moduleSupportedPlatforms(this.name)
  private static instance: BlockLogin

  config: Config = {
    enabled: true,
  }

  /**
   * 获取单例实例
   */
  public static getInstance(): BlockLogin {
    if (!BlockLogin.instance) {
      BlockLogin.instance = new BlockLogin()
    }
    return BlockLogin.instance
  }

  destroy(): void {
    super.destroy()
  }

  core(): void {
    this.loadConfig()

    if (!this.config.enabled)
      return

    this.closeLoginModal()
  }

  onToggleCallback(_id: string, checked: boolean): void {
    super.onToggleCallback(_id, checked)
  }

  /**
   * 关闭登录弹窗提示
   */
  closeLoginModal(): void {}

  applyConfig(config: Partial<Config>): void {
    super.updateConfig(config)
    this.closeLoginModal()
    logger.info(`[${this.name}] Config updated and apply`, this.config)
  }
}
